<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户id" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目id" prop="regionId">
        <el-input
          v-model="queryParams.regionId"
          placeholder="请输入项目id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="修改价格" prop="updatePrice">
        <el-input
          v-model="queryParams.updatePrice"
          placeholder="请输入修改价格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="原始价格" prop="originalPrice">
        <el-input
          v-model="queryParams.originalPrice"
          placeholder="请输入原始价格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="优惠的金额" prop="discountPrice">
        <el-input
          v-model="queryParams.discountPrice"
          placeholder="请输入优惠的金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="购物车类型(CLOUD_SERVER云服务器 MARKET_CLOUD市场云 GOV_CLOUD政务云)" prop="shoppingCarEnums">
        <el-input
          v-model="queryParams.shoppingCarEnums"
          placeholder="请输入购物车类型(CLOUD_SERVER云服务器 MARKET_CLOUD市场云 GOV_CLOUD政务云)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单摘要" prop="orderAbstract">
        <el-input
          v-model="queryParams.orderAbstract"
          placeholder="请输入订单摘要"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="折扣" prop="discount">
        <el-input
          v-model="queryParams.discount"
          placeholder="请输入折扣"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="政务云/云市场id" prop="relationId">
        <el-input
          v-model="queryParams.relationId"
          placeholder="请输入政务云/云市场id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否自动续费，默认不自动续费" prop="autoRenew">
        <el-input
          v-model="queryParams.autoRenew"
          placeholder="请输入是否自动续费，默认不自动续费"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="购买的期限数量" prop="periodNum">
        <el-input
          v-model="queryParams.periodNum"
          placeholder="请输入购买的期限数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:copy1:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:copy1:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:copy1:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:copy1:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="copy1List" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="购物车主键" align="center" prop="shoppingCarId" />
      <el-table-column label="用户id" align="center" prop="userId" />
      <el-table-column label="项目id" align="center" prop="regionId" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="创建服务器json 购物车类型为：CLOUD_SERVER时使用该字段" align="center" prop="jsonStr" />
      <el-table-column label="修改价格" align="center" prop="updatePrice" />
      <el-table-column label="原始价格" align="center" prop="originalPrice" />
      <el-table-column label="优惠的金额" align="center" prop="discountPrice" />
      <el-table-column label="购物车类型(CLOUD_SERVER云服务器 MARKET_CLOUD市场云 GOV_CLOUD政务云)" align="center" prop="shoppingCarEnums" />
      <el-table-column label="订单摘要" align="center" prop="orderAbstract" />
      <!-- <el-table-column label="折扣" align="center" prop="discount" /> -->
      <el-table-column label="政务云/云市场id" align="center" prop="relationId" />
      <el-table-column label="是否自动续费，默认不自动续费" align="center" prop="autoRenew" />
      <el-table-column label="购买的期限数量" align="center" prop="periodNum" />
      <el-table-column label="购买方式" align="center" prop="periodType" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:copy1:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:copy1:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改购物车对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户id" />
        </el-form-item>
        <el-form-item label="项目id" prop="regionId">
          <el-input v-model="form.regionId" placeholder="请输入项目id" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="创建服务器json 购物车类型为：CLOUD_SERVER时使用该字段" prop="jsonStr">
          <el-input v-model="form.jsonStr" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="修改价格" prop="updatePrice">
          <el-input v-model="form.updatePrice" placeholder="请输入修改价格" />
        </el-form-item>
        <el-form-item label="原始价格" prop="originalPrice">
          <el-input v-model="form.originalPrice" placeholder="请输入原始价格" />
        </el-form-item>
        <el-form-item label="优惠的金额" prop="discountPrice">
          <el-input v-model="form.discountPrice" placeholder="请输入优惠的金额" />
        </el-form-item>
        <el-form-item label="购物车类型(CLOUD_SERVER云服务器 MARKET_CLOUD市场云 GOV_CLOUD政务云)" prop="shoppingCarEnums">
          <el-input v-model="form.shoppingCarEnums" placeholder="请输入购物车类型(CLOUD_SERVER云服务器 MARKET_CLOUD市场云 GOV_CLOUD政务云)" />
        </el-form-item>
        <el-form-item label="订单摘要" prop="orderAbstract">
          <el-input v-model="form.orderAbstract" placeholder="请输入订单摘要" />
        </el-form-item>
        <!-- <el-form-item label="折扣" prop="discount">
          <el-input v-model="form.discount" placeholder="请输入折扣" />
        </el-form-item> -->
        <el-form-item label="政务云/云市场id" prop="relationId">
          <el-input v-model="form.relationId" placeholder="请输入政务云/云市场id" />
        </el-form-item>
        <el-form-item label="是否自动续费，默认不自动续费" prop="autoRenew">
          <el-input v-model="form.autoRenew" placeholder="请输入是否自动续费，默认不自动续费" />
        </el-form-item>
        <el-form-item label="购买的期限数量" prop="periodNum">
          <el-input v-model="form.periodNum" placeholder="请输入购买的期限数量" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCopy1, getCopy1, delCopy1, addCopy1, updateCopy1 } from "@/api/system/copy1";

export default {
  name: "Copy1",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 购物车表格数据
      copy1List: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        regionId: null,
        jsonStr: null,
        updatePrice: null,
        originalPrice: null,
        discountPrice: null,
        shoppingCarEnums: null,
        orderAbstract: null,
        discount: null,
        relationId: null,
        autoRenew: null,
        periodNum: null,
        periodType: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询购物车列表 */
    getList() {
      this.loading = true;
      listCopy1(this.queryParams).then(response => {
        this.copy1List = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        shoppingCarId: null,
        userId: null,
        regionId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        jsonStr: null,
        updatePrice: null,
        originalPrice: null,
        discountPrice: null,
        shoppingCarEnums: null,
        orderAbstract: null,
        discount: null,
        relationId: null,
        autoRenew: null,
        periodNum: null,
        periodType: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.shoppingCarId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加购物车";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const shoppingCarId = row.shoppingCarId || this.ids
      getCopy1(shoppingCarId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改购物车";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.shoppingCarId != null) {
            updateCopy1(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCopy1(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const shoppingCarIds = row.shoppingCarId || this.ids;
      this.$modal.confirm('是否确认删除购物车编号为"' + shoppingCarIds + '"的数据项？').then(function() {
        return delCopy1(shoppingCarIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/copy1/export', {
        ...this.queryParams
      }, `copy1_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
